﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Feedback.DataAccess;

namespace Feedback.Business
{
    public class BusinessLogic
    {
        public List<DataAccess.Business> GetBusiness()
        {
            using (var context = new FeedbackContextEx())
            {
                return context.Businesses.ToList();
            }
        }

        public bool SaveBusiness(DataAccess.Business business)
        {
            using (var context = new FeedbackContextEx())
            {
                context.Businesses.AddObject(business);
                return context.SaveChanges() > 0;
            }
        }

        public bool IsBusinessEmailAddressExist(string value)
        {
            using (var context = new FeedbackContextEx())
            {
                return context.BusinessIdentifications.Any(bi => bi.BusinessEmail == value);
            }
        }

        public bool IsValidBusiness(string email, string password, ref int businessId)
        {
            using (var context = new FeedbackContextEx())
            {
                var business = context.Businesses.FirstOrDefault(b => b.Login == email && b.Password == password);
                if(business != null)
                {
                    businessId = business.Id;
                    return true;
                }
            }
            return false;
        }
    }
}
